/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HightScores.java
 *
 * Created on Sep 2, 2011, 8:51:10 PM
 */
package cw.ui;

import cw.biz.GameResultBiz;
import cw.biz.PuzzleSizeBiz;
import cw.entity.GameResult;
import cw.entity.PuzzleSize;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import javax.swing.JLabel;

/**
 *
 * @author BAOBAO
 */
public final class HighScores extends javax.swing.JPanel {

    LinkedList<JLabel> list_player = new LinkedList<JLabel>();
    LinkedList<JLabel> list_score = new LinkedList<JLabel>();

    /** Creates new form HightScores */
    public HighScores() {
        initComponents();
        addListHightScore();
        clearScore();
        displayHightScores(1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblPlayer1 = new javax.swing.JLabel();
        lblPlayer2 = new javax.swing.JLabel();
        lblPlayer3 = new javax.swing.JLabel();
        lblPlayer4 = new javax.swing.JLabel();
        lblPlayer5 = new javax.swing.JLabel();
        lblPlayer6 = new javax.swing.JLabel();
        lblScore1 = new javax.swing.JLabel();
        lblScore2 = new javax.swing.JLabel();
        lblScore3 = new javax.swing.JLabel();
        lblScore4 = new javax.swing.JLabel();
        lblScore5 = new javax.swing.JLabel();
        lblScore6 = new javax.swing.JLabel();
        lblBackground = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(600, 650));
        setPreferredSize(new java.awt.Dimension(600, 650));
        setLayout(null);

        lblPlayer1.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer1.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer1.setText("Player");
        add(lblPlayer1);
        lblPlayer1.setBounds(110, 140, 140, 20);

        lblPlayer2.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer2.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer2.setText("Player");
        add(lblPlayer2);
        lblPlayer2.setBounds(110, 170, 140, 20);

        lblPlayer3.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer3.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer3.setText("Player");
        add(lblPlayer3);
        lblPlayer3.setBounds(110, 200, 140, 20);

        lblPlayer4.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer4.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer4.setText("Player");
        add(lblPlayer4);
        lblPlayer4.setBounds(110, 230, 140, 20);

        lblPlayer5.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer5.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer5.setText("Player");
        add(lblPlayer5);
        lblPlayer5.setBounds(110, 260, 140, 20);

        lblPlayer6.setFont(new java.awt.Font("Arial", 3, 11));
        lblPlayer6.setForeground(new java.awt.Color(255, 255, 255));
        lblPlayer6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/medal.png"))); // NOI18N
        lblPlayer6.setText("Player");
        add(lblPlayer6);
        lblPlayer6.setBounds(110, 290, 140, 20);

        lblScore1.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore1.setForeground(new java.awt.Color(255, 255, 255));
        lblScore1.setText("Player");
        add(lblScore1);
        lblScore1.setBounds(330, 140, 140, 20);

        lblScore2.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore2.setForeground(new java.awt.Color(255, 255, 255));
        lblScore2.setText("Player");
        add(lblScore2);
        lblScore2.setBounds(330, 170, 140, 20);

        lblScore3.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore3.setForeground(new java.awt.Color(255, 255, 255));
        lblScore3.setText("Player");
        add(lblScore3);
        lblScore3.setBounds(330, 200, 140, 20);

        lblScore4.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore4.setForeground(new java.awt.Color(255, 255, 255));
        lblScore4.setText("Player");
        add(lblScore4);
        lblScore4.setBounds(330, 230, 140, 20);

        lblScore5.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore5.setForeground(new java.awt.Color(255, 255, 255));
        lblScore5.setText("Player");
        add(lblScore5);
        lblScore5.setBounds(330, 260, 140, 20);

        lblScore6.setFont(new java.awt.Font("Arial", 3, 11));
        lblScore6.setForeground(new java.awt.Color(255, 255, 255));
        lblScore6.setText("Player");
        add(lblScore6);
        lblScore6.setBounds(330, 290, 140, 20);

        lblBackground.setFont(new java.awt.Font("Arial", 3, 11));
        lblBackground.setForeground(new java.awt.Color(255, 255, 255));
        lblBackground.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/high-score.png"))); // NOI18N
        add(lblBackground);
        lblBackground.setBounds(0, 0, 530, 430);
    }// </editor-fold>//GEN-END:initComponents

    public void displayHightScores(int type_puzzle) {
        try {
            int i = 0;
            GameResultBiz resultBiz = new GameResultBiz();
            List<GameResult> lstResult = new ArrayList<GameResult>();
            lstResult = resultBiz.getHightScores(type_puzzle);
            clearScore();
            for (i = 0; i < lstResult.size(); i++) {
                list_player.get(i).setVisible(true);
                list_score.get(i).setVisible(true);

                list_player.get(i).setText(lstResult.get(i).getUserName());
                list_score.get(i).setText("" + lstResult.get(i).getScore());
            }
            for (int k = i; k < list_player.size(); k++) {
                list_player.get(k).setVisible(true);
                list_score.get(k).setVisible(true);
                list_player.get(k).setText("N/A");
                list_score.get(k).setText("N/A");
            }
        } catch (Exception e) {
//            Logger.getLogger(HighScores.class.getName()).log(java.util.logging.Level.SEVERE, null, e);
        }

    }

    public void addListHightScore() {
        list_player.add(lblPlayer1);
        list_player.add(lblPlayer2);
        list_player.add(lblPlayer3);
        list_player.add(lblPlayer4);
        list_player.add(lblPlayer5);
        list_player.add(lblPlayer6);

        list_score.add(lblScore1);
        list_score.add(lblScore2);
        list_score.add(lblScore3);
        list_score.add(lblScore4);
        list_score.add(lblScore5);
        list_score.add(lblScore6);
    }

    public void clearScore() {
        for (int i = 0; i < list_player.size(); i++) {
            list_player.get(i).setVisible(false);
            list_score.get(i).setVisible(false);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblBackground;
    private javax.swing.JLabel lblPlayer1;
    private javax.swing.JLabel lblPlayer2;
    private javax.swing.JLabel lblPlayer3;
    private javax.swing.JLabel lblPlayer4;
    private javax.swing.JLabel lblPlayer5;
    private javax.swing.JLabel lblPlayer6;
    private javax.swing.JLabel lblScore1;
    private javax.swing.JLabel lblScore2;
    private javax.swing.JLabel lblScore3;
    private javax.swing.JLabel lblScore4;
    private javax.swing.JLabel lblScore5;
    private javax.swing.JLabel lblScore6;
    // End of variables declaration//GEN-END:variables
}
